﻿using System.Collections.Generic;
using UnityEngine;
using Random = System.Random;


namespace Const
{
    public static class Param
    {
        //每个块的水平间隔
        public const float interval = 2.5f;

        //块的数量
        public const int cubeCount = 15;

        public const float playerSpeed = 10f;

        public const float drawLineSpeed = 0.3f;

        public static Vector3 forward = new Vector3(0.5f, 1 ,0);
    }


    public enum EState
    {
        START,
        ING,
        END,
    }


    public static class MyColor
    {
        private static readonly Dictionary<string, int> _colorDic = new Dictionary<string, int>()
        {
            {"red", 0xf25346},
            {"white", 0xd8d0d1},
            {"brown", 0x59332e},
            {"pink", 0xf8986e},
            {"brownDark", 0x23190f},
            
            {"blue", 0x1a237e},
            {"blue_light", 0x1565c0},
            {"blue_dark", 0x000051}
        };

        public static Color GetColor(string str)
        {
            return TranslateColor(_colorDic[str]);
        }

        public static Color GetRandomColor()
        {
            var list = new List<string>(_colorDic.Keys);
            var random = new Random().Next(0, list.Count);
            var color = _colorDic[list[random]];
            return TranslateColor(color);
        }

        private static Color TranslateColor(int color)
        {
            var r = ((color >> 16) & 0xff) / 255f;
            var g = ((color >> 8) & 0xff) / 255f;
            var b = ((color) & 0xff) / 255f;
            return new Color(r, g, b, 1.0f);
        }
        
        public static void SetMatrialColor(GameObject gameObject, Color color)
        {
            if (gameObject == null)
            {
                return;
            }

            var material = gameObject.GetComponent<MeshRenderer>().material;
            if (material == null)
            {
                return;
            }

            material.color = color;
        }
        
        public static void SetMatrialColor(GameObject gameObject, string str)
        {
            if (gameObject == null)
            {
                return;
            }

            var color = GetColor(str);

            var material = gameObject.GetComponent<MeshRenderer>().material;
            if (material == null)
            {
                return;
            }

            material.color = color;
        }
    }
}